<?php
include_once IR.'functions/common/cache_info.func.php';
include_once IR.'functions/user/user_session.func.php';

//先检查cookie
$new_pp_uid = 0;
if (isset($_COOKIE['super_mod']) && $_COOKIE['super_mod']==1){
    $g_version_op = 0;
    $g_version_flag = 0; 
}
if (isset($_COOKIE[$zone_id.'SAL'])) {
	//取cookie
	//cookie解密
	$cookie = get_cookie();
	$uid = $cookie[0];
	$sid = $cookie[1];
	$cid = $cookie[2];
	
	$pp_uid = $cookie[3];
        $online_id = $cookie[4];
	if($g_version_op==1){
            if($new_pp_uid==$pp_uid){
                set_cookie($uid, $sid, $cid,$pp_uid,$online_id);
            }else{
                $uid = 0;
                set_cookie(0, 0, 0,0,0);
            }
	}else{
		set_cookie($uid, $sid, $cid,$pp_uid,$online_id);
	}
	//标志
} else {
	$uid = 0;
	$sid = 0;
	$cid = 0;
	$pp_uid = 0;
    set_cookie(0, 0, 0,0); 
}

if ($uid == 0){
	//未登录逻辑
    if ($g_module!='account'){ 
		return_no_login($g_view); 
    }
}else{
    if ($config['maintain_work']&&!in_array($pp_uid,$config_main_pp_uid) && (!isset($_COOKIE['super_mod']) || $_COOKIE['super_mod']!=1)){ 
        return_maintain_work($g_view);		 
    } else {
        //服务器校验session		 
        if (!$result = check_user_online($uid,$sid)) {
            if($g_module!='reg'&&$g_module!='account'){
                $uid = 0;
                set_cookie(0, 0, 0,0);			 
                return_no_login($g_view);
            }
        }
        $g_user_base = user_get_user_base($uid);
        $g_user_extend = user_get_user_extend($uid);
        update_online_info($uid,$g_user_extend,$zeit,$online_id);
        
		$user_key = md5($uid.$public_key);
            
        //判断连续登录，加载成就的hook
        $last_online_detail = $g_user_extend['last_online'];
        $days_last_online = ($last_online_detail - $last_online_detail%86400)/86400;
        $days_now_online = ($zeit - $zeit % 86400)/86400;
        
    }
}

$browser = common_get_user_browser();

$g_sunrise = $zeit-($zeit+8*3600)%86400;
$g_sunset = $g_sunrise + 86399;
?>
